﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AIForwardDetector : MonoBehaviour {
    public AIController aIController;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    private void OnTriggerEnter(Collider other)
    {
        if(other.CompareTag("Barrier"))
        {
            aIController.Jump();
        }
    }

    private void OnTriggerStay(Collider other)
    {
        if(other.CompareTag("Border"))
        {
            if(aIController.isInTurnState)
            {
                if (aIController.isTurnRight)
                {
                    aIController.TurnRight();
                }
                else
                    aIController.TurnLeft();
            }
            else
            {
                aIController.isTurnRight = aIController.canTurnRight;
                aIController.isInTurnState = true;
            }
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Border"))
        {
            aIController.isInTurnState = false;
        }
    }
}
